package com.four;

public class Ticket implements Runnable{
	private int ticket=100;
	private String key="";
	
	public void run() {
		while(ticket>0) {
			this.buyticket();
		}
		
	}
	
	public  void buyticket() {
		try {
			if(ticket>0) {
				synchronized(key) {
			ticket--;
			System.out.println(Thread.currentThread().getName()+":"+this.ticket);
				}
		    Thread.sleep(700);
			}
		
		
		}catch(Exception e) {
			e.printStackTrace();
		}
		
		
		
		
		
	}
	
	
	
}
